"""
@author: 江同学呀
@file: object_field.py
@date: 2024/7/26 11:13
@desc:
    https://www.elastic.co/guide/en/elasticsearch/reference/7.17/object.html

    Defines a parent/child relationship for documents in the same index.
    定义同一索引中文档的父/子关系。
"""
from abc import ABC
from typing import Type, Union, Dict

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField
from espc.orm.model.mapping.field.field_attribute import EagerGlobalOrdinalsAttribute
from espc.utils.build_add_attr import build_add_attr


class JoinField(_BaseField, EagerGlobalOrdinalsAttribute, ABC):
    """
    连接 字段
    todo 特殊字段类型，未仔细研究文档
    """
    _field_type: str = "join"

    def __init__(
            self, field_name: str = None, value: Dict = None, default: Dict = None, eager_global_ordinals: bool = None,
    ):
        super().__init__(
            field_name=field_name, value=value, default=default, eager_global_ordinals=eager_global_ordinals
        )
        return

    def __get__(self, instance: _Base, owner: Type["JoinField"]) -> Union["JoinField", Dict]:
        return super(JoinField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: Dict):
        super(JoinField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> Dict:
        return self._value

    @value.setter
    def value(self, value: Dict):
        self._value: Dict = value
        return

    @build_add_attr
    def _build(self) -> Dict:
        raise NotImplementedError(f"{self.__class__.__name__}：特殊字段类型，未仔细研究文档")




































